import WeatherBox from '../WeatherBox/WeatherBox';

export default class RoadWeatherHandler {
    constructor() {
        this.chart = null;
        this.infoObj = null;
        this.areaName = '';
        this.adcode = '';
    }

    loadData(lng, lat, isInitChart) {
        // let that = this;
        // minemap.util.getJSON('//minedata.cn/service/search/adminByPoint?token=a3622f2702c34957a160242d2eb0e508&location=' + lng + ',' + lat, function (error, data) {
        //     const areaName = data ? data.data.areaname : '';
        //     const adcode = data ? data.data.adcode : '';
        //     minemap.util.getJSON('//dev.minedata.cn/dataweather/adminweather/' + adcode, function (error, data) {
        //         if (error) {
        //             console.log(error)
        //         } else {
        //             that.infoObj = data;
        //             that.areaName = areaName;
        //             that.adcode = adcode;
        //             if (isInitChart) {
        //                 that.updateChart();
        //             }
        //         }
        //     });
        // });
        let that = this;
        minemap.util.getJSON('../data/weather.json', function (error, data) {
            if (error) {
                console.log(error)
            } else {
                that.infoObj = data;
                that.areaName = '西安市';
                that.adcode = '610100';
                if (isInitChart) {
                    that.updateChart();
                }
            }
        });
    }

    updateChart() {
        this.chart = new WeatherBox('weather-chart', this.infoObj, this.areaName, this.adcode);
    }

    getInfoObj() {
        return this.infoObj;
    }

    getChart() {
        return this.chart;
    }
}